package com.qf.oa_system.controller;

import com.qf.oa_system.entity.Student;
import com.qf.oa_system.entity.User;
import com.qf.oa_system.service.RolesService;
import com.qf.oa_system.service.StudentService;
import com.qf.oa_system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("public")
public class PublicController {

    @Autowired
    RolesService rolesService;
    @Autowired
    StudentService studentService;
    @Autowired
    UserService userService;

    @GetMapping("personaldata")
    public String test(HttpSession session, HttpServletRequest request){
        String role = (String)session.getAttribute("role");
        System.out.println(" 权限"+role);
        User user = (User)session.getAttribute("user");
        System.out.println("打印user信息"+user);
        Student student = new Student();
        student.setUserId(user.getUserId());

        Student students = studentService.queryAllByUserId(user.getUserId());
        request.setAttribute("student", students);
        return role+"_personaldata";
    }
    @GetMapping("test1")
    public String test1(){
        Student student = studentService.queryAllByUserId(7);
        System.out.println(student);
        return "hello";
    }
}
